<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body,html{
            margin: 0;
            padding: 0;
            overflow: hidden;
            height: 100%;
            background: black;
        }
        .fall{
            background: white;
            position: absolute;
            width: 20px;
            height: 20px;
            border-radius: 50%;
        }
    </style>
</head>
<body>
     <script>
        //获取屏幕宽高
        var windowWidth = window.screen.width;
        var windowHeight = window.screen.height;
 
        //创建飘落物体
        function createFall(){
            var left = 0;
            var top = 0;
 
            //定义一个初始化随机数,使飘落物体在屏幕中
            var left_random = Math.random() * windowWidth;
            var top_random = Math.random()* windowHeight;
            var div = document.createElement('div');
            div.className = 'fall';
            div.style.transform = 'scale('+(Math.random())+')'
 
            document.body.appendChild(div);
 
            //飘落
            setInterval(function () {
 
                div.style.left = left_random + left +'px';
                div.style.top = top_random + top +'px';
                left += 0.2;
                top += 0.2;
 
                //如果飘落物体跑到屏幕外面了,让飘落物体重新返回屏幕顶部
                if(left_random + left >= windowWidth){
                    left_random = Math.random();
                    left = 0;
                }
 
                if(top_random + top >= windowHeight){
                    top_random = Math.random();
                    top = 0;
                }
            },10)
 
        }
        for(var i = 0 ; i < 200 ; i++){
            createFall();
        }
    </script>
</body>
</html>
